
package com.vids.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.vids.mapper.MotorVehicleMapper;
import com.vids.model.entity.MotorVehicle;
import com.vids.model.param.MotorVehicleBatchModel;
import com.vids.model.param.MotorVehicleBatchParam;
import com.vids.model.param.MotorVehicleModel;
import com.vids.model.param.SubImageBatchParam;
import com.vids.model.vo.SubImageInfoVo;
import com.vids.service.IImageBusinessService;
import com.vids.service.IMotorVehicleService;
import com.vids.utils.BeanUtilss;
import com.vids.utils.QueryUtils;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 机动车 服务实现类
 * </p>
 *
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class MotorVehicleServiceImpl extends ServiceImpl<MotorVehicleMapper, MotorVehicle>
	implements IMotorVehicleService {

    public final static String type = "01";

    private final MotorVehicleMapper motorVehicleMapper;

    private final IImageBusinessService tBigDataImageBusinessServiceImpl;

    @Override
    public MotorVehicle findByMotorVehicleID(String MotorVehicleID) {
	return baseMapper.findByMotorVehicleID(MotorVehicleID);
    }

    @Override
    public void deleteByMotorVehicleID(String MotorVehicleID) {
	baseMapper.deleteByMotorVehicleID(MotorVehicleID);
    }

    /*
     * List<SubImageInfoVo> volist = tBigDataImageBusinessServiceImpl
     * .findSubImageInfoVo(row.getMotorVehicleID(), type);
     */

    @Override
    public MotorVehicleBatchParam getMotorVehicleList(Map<String, Object> map) {
	// 无条件查询默认返回所有
	if (map == null || map.size() == 0) {
	    List<MotorVehicle> resultList = motorVehicleMapper.findAll();
	    return buildResultModel(resultList);
	}
	Map<String, Object> paramMap = QueryUtils.buildParam(map);
	List<MotorVehicle> resultList = motorVehicleMapper.getMotorVehicleList(paramMap);
	return buildResultModel(resultList);
    }

    private MotorVehicleBatchParam buildResultModel(List<MotorVehicle> resultList) {
	if (resultList != null && resultList.size() > 0) {
	    MotorVehicleBatchParam param = new MotorVehicleBatchParam();
	    MotorVehicleBatchModel batchModel = new MotorVehicleBatchModel();
	    List<MotorVehicleModel> modelList = new ArrayList<>();
	    for (MotorVehicle car : resultList) {
		MotorVehicleModel model = BeanUtilss.transferObjectCommon(car, MotorVehicleModel.class);
		List<SubImageInfoVo> volist = tBigDataImageBusinessServiceImpl
			.findSubImageInfoVo(car.getMotorVehicleID(), type);
		SubImageBatchParam imageBatchParam = new SubImageBatchParam();
		imageBatchParam.setSubImageInfoObject(volist);
		model.setSubImageList(imageBatchParam);
		modelList.add(model);
	    }
	    batchModel.setMotorVehicleObject(modelList);
	    param.setMotorVehicleListObject(batchModel);
	    return param;
	}
	return null;
    }
}
